package com.ag.lwc.action;

import java.util.LinkedList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.ag.bean.TbEventSource;
import com.ag.common.BaseAction;
import com.ag.lwc.service.EventSourceService;

@Controller("EventSourceAction")
public class EventSourceAction extends BaseAction 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5693982287071850066L;
	@Resource(name="EventSourceService")
	private EventSourceService service;
	private List<TbEventSource> result = new LinkedList<TbEventSource>();
	private String message;
	private String esId;
	private String esEventSource;
	
	public String find()
	{
		result = service.findAll();
		message = "find_success";
		return "find_success";
	}
	public String modify()
	{
		TbEventSource tbEventSource = new TbEventSource();
		tbEventSource.setEsId(esId);
		tbEventSource.setEsEventSource(esEventSource);
		try
		{
			service.update(tbEventSource);
			message="change_success";
			
		}
		catch(Exception e)
		{
			message="修改失败";
			
		}
		return "change_success";
	}
	public String save()
	{
		TbEventSource tbEventSource = new TbEventSource();
		tbEventSource.setEsId(esId);
		tbEventSource.setEsEventSource(esEventSource);
	
		try
		{
		
			service.save(tbEventSource);
			message= "save_success";
			
		}
		catch(Exception e)
		{
			message="保存失败";
			
		}
		return "save_success";
	}
	public String delete()
	{
		try
		{
			service.delete(esId);
			message = "delete_success";
			
		}
		catch(Exception e)
		{
			message="删除失败";
			
		}
		return "delete_success";	
	}
	public String execute()
	{
		result = service.findAll();
		return "success";
	}
	public List<TbEventSource> getResult() {
		return result;
	}
	public void setService(EventSourceService service) {
		this.service = service;
	}
	public String getMessage() {
		return message;
	}
	public void setEsId(String esId) {
		this.esId = esId;
	}
	public void setEsEventSource(String esEventSource) {
		this.esEventSource = esEventSource;
	}
	
}
